package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Notes;
import org.akomantoso.core.data.group.ANpopup;
import org.akomantoso.core.data.type.PlacementType;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;
import org.akomantoso.core.visitor.AKVisitor;

/**
 * The element authorialNote is a popup element containing an authorial (non-editorial) note in the main flow of the
 * text..
 * 
 * <pre>
 *  <xsd:element name="authorialNote">
 * 		<xsd:complexType>
 * 			<xsd:complexContent>
 * 				<xsd:extension base="popupStructure">
 * 					<xsd:attributeGroup ref="notes"/>
 * 				</xsd:extension>
 * 			</xsd:complexContent>
 * 		</xsd:complexType>
 * 	</xsd:element>
 * </pre>
 * 
 * @author <a href="mailto:jacques.militello@gmail.com">Jacques Militello</a>
 * 
 * @since http://www.akomantoso.org/1.0
 */
public final class AuthorialNote extends PopupStructure implements Notes , ANpopup {

	public static final String ELEMENT = "authorialNote";

	private String _marker;
	private PlacementType _placement;
	private String _placementBase;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getMarker()
	 */
	@Override
	public String getMarker() {
		return _marker;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setMarker(java.lang.String)
	 */
	@Override
	public void setMarker(String marker) {
		_marker = marker;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getPlacement()
	 */
	@Override
	public PlacementType getPlacement() {
		return _placement;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setPlacement(org.akomantoso.core.data.type.PlacementType)
	 */
	@Override
	public void setPlacement(PlacementType placement) {
		_placement = placement;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#getPlacementBase()
	 */
	@Override
	public String getPlacementBase() {
		return _placementBase;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Notes#setPlacementBase(java.lang.String)
	 */
	@Override
	public void setPlacementBase(String placementBase) {
		_placementBase = placementBase;
	}

	/**
	 * @see org.akomantoso.core.data.PopupStructure#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		out.writeStart(ELEMENT);
		OutputUtil.writeNotes(out,this);
		super.writeExternal(out);
		out.writeEnd();
	}

	/**
	 * @see org.akomantoso.core.data.PopupStructure#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_marker = in.readAttribute(Notes.ATTRIBUTE_MARKER);
		_placementBase = in.readAttribute(Notes.ATTRIBUTE_PLACEMENT_BASE);
		_placement = PlacementType.checkValueOf(in.readAttribute(Notes.ATTRIBUTE_PLACEMENT));
		super.readExternal(in);
	}

	/**
	 * @see org.akomantoso.core.visitor.AKVisitable#accept(org.akomantoso.core.visitor.AKVisitor)
	 */
	@Override
	public void accept(AKVisitor visitor) {
		if (visitor.visitBegin(this)) {
			internalAccept(visitor);
			visitor.visitEnd(this);
		}
	}
	
}